﻿using System;
using System.Collections.Generic;
using NHunspell;

namespace KnowledgeSource
{
    public class VerbToInfinitive // : IKnowledgeSource
    {
        private Hunspell hunspell;
        private Utils util;
        private int MAX_COUNT = 3;
        public VerbToInfinitive(Hunspell hunspell, MyThes thes)
        {
            
            this.hunspell = hunspell;
            util = new Utils();
        }

        public List<string> execute(string input)
        {
            var sentence = util.MakeListStringFromSentence(input);
            var possibleResults = new List<List<string>>();
            int actualWord = 0;
            
            try
            {
                foreach (var word in sentence)
                {
                    List<string> stems = hunspell.Stem(word);
                    possibleResults.Add(new List<string>());

                    if (stems.Count != 0 && word.Length >= 3)
                    {
                        possibleResults[actualWord].AddRange(stems.GetRange(0, MAX_COUNT > stems.Count ? stems.Count : MAX_COUNT ));
                    }
                    else
                    {
                        var x = new List<string>();
                        x.Add(word);
                        possibleResults[actualWord].AddRange(x);
                    }
                    actualWord++;
                }

                var temp = util.CreateSentenceFromAllPosibilities(possibleResults);
                return temp;
            }
            catch (Exception ex)
            {
                var t = new List<string>();
                t.Add(input);
                return t;
            }
        }
    }
}
